from django.contrib.auth.models import AbstractUser
from django.db import models
from common.db import BaseModel


class UserProfile(AbstractUser, BaseModel):
    mobile = models.CharField(max_length=11, null=True, blank=True, verbose_name="手机号")
    avatar = models.ImageField(null=True, blank=True, max_length=200, verbose_name="用户头像")
    nick_name = models.CharField(max_length=50, null=True, blank=True, verbose_name="用户昵称")

    class Meta:
        db_table = "user"
        verbose_name = "用户"
        verbose_name_plural = verbose_name
        # 自定义权限
        permissions = (
            ("export_userprofile", "导出用户"),
            ("upload_userprofile", "导入用户"),
        )

    def roles_list(self):
        return [{'id': role.id, 'name': role.name} for role in self.roles.all()]
